import { State } from "framework/FSM/AState";
import { ActionArgHelper } from "../../../ActionManager/ActionArgHelper";
import { EntityHelper } from "utils/entity/EntityHelper";
import { PositionHelper } from "utils/position/PositionHelper";
 

/**
Claim Body 的任务
 */ 
export class ClaimTask<T extends IStateArg<Creep>>  extends State<T>
{

    //
    public  getActions(arg:T):Action[]
    {
        
        const memory = arg.entity.getNodeMemory();
        if(!memory.taskid)
        {
            return [];
        }
        const task =arg.task as ITask<ICreepTaskData<"claim">>;
        if(!task)
        {
            // 查找不到任务
            return []
        }
        const targetRoom = Game.rooms[task.data.arg.room] as Required<Room>;
        
        if(targetRoom)
        {
            return [ActionArgHelper.actionController(arg.entity,targetRoom.controller,task.data.arg.action)]
        }
        else
        {
            const pos = PositionHelper.Create({roomName:task.data.arg.room,x:25,y:25});
            if(task.data.arg.action == "claim")
            {
                // 取消可视化 ActionArgHelper.actionVisualHostile(arg.entity.room)
                return [ActionArgHelper.actionMoveto(arg.entity,{pos: pos,range:10},{IsEludeHostile:true,IsRealtime:true,portal:task.data.portal})
                ]
            }
            return [ActionArgHelper.actionMoveto(arg.entity,{pos: pos,range:10},{})]
        }

    }
}
